package com.twu.biblioteca;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

/**
 * Created with IntelliJ IDEA.
 * User: ysotirov
 * Date: 30/01/13
 * Time: 19:09
 * To change this template use File | Settings | File Templates.
 */
public class IOHandler implements IOInterface {
  //  ArrayList<String> printQueue = new ArrayList<String>();
    BufferedReader bufferRead = new BufferedReader(new InputStreamReader(System.in));


    public void queueMsg(String msg){
        printQueue.add(msg);
    }

    public void Print(){
        if (!printQueue.isEmpty()){
            for (int i=0; i<printQueue.size(); i++)
                System.out.println(printQueue.get(i));
            printQueue.clear();
        }
    }


    public int getInput(){
        String opt = "";
        String msg = "Please input a valid option!";

        try {
            opt = bufferRead.readLine();

        }
        catch(IOException e)
        {
            e.printStackTrace();
            printQueue.add(msg);
            Print();
        }


        return Integer.parseInt(opt);
    }

    public String getUserCredentials(){
        String credential="";
        try {
            credential = bufferRead.readLine();

        }
        catch(IOException e)
        {
            e.printStackTrace();
            printQueue.add(credential.substring(0,7));
            Print();
        }


        return credential;

    }


//    public boolean validInput(int opt, ArrayList validList){
//        if ((opt>0) && (opt<=validList.size())) return true;
//        return false;
//    }
}
